'''
Created on 2018年3月23日

@author: houzw
'''
import requests  
import itchat  
  
KEY = 'dbbbdb23133b4082ae5cb7dd448dbc6a'  
  
def get_response(msg):  
    apiUrl = 'http://www.tuling123.com/openapi/api'  
    data = {  
        'key': KEY,  
        'info': msg,  
        'userid': 'pth-robot',  
    }  
    try:  
        r = requests.post(apiUrl, data=data).json()  
        return r.get('text')  
    except:  
        return  
 
 
@itchat.msg_register(itchat.content.TEXT)  
def tuling_reply(msg):  
    defaultReply = 'I received: ' + msg['Text']  
    reply = get_response(msg['Text'])  
    return reply or defaultReply  
  
itchat.auto_login(hotReload=True)  
itchat.run()  